<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="searchText" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="applyAlter-query">
                    <i class="layui-icon layui-icon-search"></i>
                   	 查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
					重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="applyAlter-table" lay-filter="applyAlter-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="applyAlter-toolbar">
    <button shiro:hasPermission="gen:applyAlter:add" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
		 新增
    </button>
    <button shiro:hasPermission="gen:applyAlter:remove" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
        <i class="layui-icon layui-icon-delete"></i>
		删除
    </button>
</script>

<script type="text/html" id="applyAlter-bar">
    {{# if(d.deptPass==0){}}
    <button shiro:hasPermission="gen:applyAlter:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" ><i class="layui-icon layui-icon-edit">审核</i>
    </button>
    {{# }else{ }}
    <button shiro:hasPermission="gen:applyAlter:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="check"><i class="layui-icon file">查看</i>
    </button>
    {{#  } }}
</script>


																																																																																																																	

<script type="text/javascript" th:inline="javascript">
	
	window.selectDictLabel=function(datas, value) {
		var actions = [];
	    $.each(datas, function(index, dict) {
	        if (dict.dictValue == ('' + value)) {
	        	var listClass = ("default"== dict.listClass) ? "" : "badge badge-" + dict.listClass;
	        	actions.push(sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
	            return false;
	        }
	    });
	    return actions.join('');
	}
	window.sprintf=function (str) {
	    var args = arguments, flag = true, i = 1;
	    str = str.replace(/%s/g, function () {
	        var arg = args[i++];
	        if (typeof arg === 'undefined') {
	            flag = false;
	            return '';
	        }
	        return arg;
	    });
	    return flag ? str : '';
	}
</script>	
	


<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
				
        let MODULE_PATH = rootPath+"/ApplyAlterDanweiController/";
        let cols = [
            [
               {type: 'checkbox'},

                {title: '序号',type: 'numbers'},
    	                	
               {title: '项目状态', field: 'state', align: 'center',
                   templet:function (d){
                       if(d.state == 0){
                           return "审核中";
                       }else if(d.state == 1){
                           return "审核通过";}
                       else if(d.state == 2){
                           return "审核不通过";
                       }
                   }
               },
                {title: '单位审核状态', field: 'deptPass', align: 'center',
                    templet:function (d){
                        if(d.deptPass == 0){
                            return "待审核";
                        }else if(d.deptPass == 1){
                            return "审核通过";}
                        else if(d.deptPass == 2){
                            return "审核不通过";
                        }
                    }
                },

                {title: '批准号', field: 'proNum', align: 'center'},

                {title: '项目名称', field: 'proName', align: 'center'},
    	                	
               {title: '项目类型', field: 'proType', align: 'center',
                   templet:function (d){
                       if(d.proType == "a"){
                           return "新型智库项目";
                       }else if(d.proType == "c"){
                           return "省级重大项目";
                       }else if(d.proType == "d"){
                           return "省级一般项目";
                       }else if(d.proType == "e"){
                           return "省级青年项目";
                       }
                   }
               },

               {title: '负责人', field: 'manName', align: 'center'},

                {title: '更新时间', field: 'deptUpdateTime', align: 'center',
                    templet : "<div>{{layui.util.toDateString(d.deptUpdateTime, 'yyyy-MM-dd')}}</div>"
                },
                    
               {title: '操作', toolbar: '#applyAlter-bar', align: 'center'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#applyAlter-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#applyAlter-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        //table图标事件绑定
        table.on('tool(applyAlter-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
            else if (obj.event === 'check') {
                window.check(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(applyAlter-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(applyAlter-query)', function (data) {
            table.reload('applyAlter-table', {page: {curr: 1}, where: data.field})
            return false;
        });


        //添加
        window.add = function () {
            var i = layer.open({
                type: 2,
                title: '选择',
                shade: 0.1,
                area: ['500px', '300px'],
                content: MODULE_PATH + 'select',
            });
        }
        //修改
        window.edit = function (obj) {
            var index =layer.open({
                type: 2,
                title: '审核',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
            layer.full(index);

        }

        //查看
        window.check = function (obj) {
            var index =layer.open({
                type: 2,
                title: '查看',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'check/' + obj.data['id']
            });
            layer.full(index);

        }

        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code==200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code==200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('applyAlter-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
        
        
        //刷新按钮
        window.refresh = function () {
            table.reload('applyAlter-table');
        }
    })
</script>
</html>